import isArray from "lodash/isArray";
/**
 * 获得计算字段Code，form-data-reload时，排除计算字段的数据覆盖
 */
function getCalculationFields({
  tplData
}){
  let calculationFields ={
    main: {},
    children:{}
  }
  var data_define = tplData.form.data_define;//业务对象定义的字段数据
  if(data_define){
    //遍历业务对象，把字段步骤权限拼接到业务对象上
    //1.处理主表
    isArray(data_define?.main?.fields) && data_define.main.fields.forEach(function(field){
      if(field?.type === "calculation"){//如果是计算字段
        calculationFields.main[field.code] = true;
      }
    })
    
    //2.处理子表
    isArray(data_define.children) && data_define.children.forEach(function(group){
      let groupCode = group.code;
      //遍历业务对象子表字段
      isArray(group.fields) && group.fields.forEach(function(field){
        if(field?.type === "calculation"){//如果是计算字段
          if(!calculationFields.children[groupCode]){
            calculationFields.children[groupCode] = {};
          }
          calculationFields.children[groupCode][field.code] = true;
        }
      })
    })
  }
  return calculationFields;
}

export {
  getCalculationFields
}